package org.sgmiller.quickstem;

import static org.sgmiller.quickstem.TransactionState.*;

class ReadCommittedTransaction extends Transaction {

	ReadCommittedTransaction(long tid, TransactionState state, boolean tracked) {
		this(IsolationLevel.READ_COMMITTED, tid, state, tracked);
	}
	
	ReadCommittedTransaction(IsolationLevel level, long tid, TransactionState state,
			boolean tracked) {
		super(level, tid, state, tracked);
	}

	ReadCommittedTransaction(boolean tracked) {
		super(IsolationLevel.READ_COMMITTED, tracked);
	}

	public ReadCommittedTransaction(long nestedTid, boolean track) {
		this(IsolationLevel.READ_COMMITTED, nestedTid, TransactionState.OPEN, track);
	}

	@Override
	protected Object consider(Stem<?> stem, Version<?> v) {
		if (v.txn.isTopLevel() || isSubtransaction(v.txn)) {
			switch (v.txn.state.ordinal) {
			case ORD_OPEN:
				if (!isRelated(v.txn))
					break;
			case ORD_COMMITTED:
				return v.value;
			}
		}			
		return VAL_CONTINUE;
	}

}
